package net.wzw.template;

import net.wzw.entity.Order;
import lombok.extern.slf4j.Slf4j;
import org.jeasy.rules.annotation.Action;
import org.jeasy.rules.annotation.Condition;
import org.jeasy.rules.annotation.Fact;
import org.jeasy.rules.api.Rule;

/**
 * @author wzw
 * @date 2025/4/2
 * @Description
 */
@Slf4j
public abstract class BasePromotionRule implements Rule {

    @Condition
    public abstract boolean matchCondition(Order order);

    @Action
    public void applyDiscountTemplate(@Fact("order") Order order) {
        order.applyDiscount(getDiscountRate());
        log.info("应用{}折扣", getRuleName());
    }

    protected abstract double getDiscountRate();

    protected abstract String getRuleName();

}
